package com.fancy.application.sys.config.controller;


import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fancy.application.common.controller.BaseController;
import com.fancy.application.common.vo.BasePage;
import com.fancy.application.common.vo.Result;
import com.fancy.application.sys.config.entity.SysConfigMain;
import com.fancy.application.sys.config.service.ISysConfigMainService;
import com.fancy.application.sys.config.vo.SysConfigMainVo;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

/**
* fancycode自动生成v1.0
* @author wison
* 2019-11-27
*/

@RestController
@RequestMapping("/sys/config/sys_config_main")
public class SysConfigMainController extends BaseController {
@Resource
private ISysConfigMainService baseService;

    @PostMapping(value = "/list")
    public Result list(@RequestBody BasePage<SysConfigMain> basePage){
        IPage<SysConfigMain> sysConfigMainPage = baseService.page(basePage.getPage(),basePage.getWrapper());
        return Result.ok(sysConfigMainPage);
    }

    @PutMapping
    public Result save(@RequestBody SysConfigMainVo sysConfigMainVo){
        SysConfigMain sysConfigMain = new SysConfigMain();
        BeanUtil.copyProperties(sysConfigMainVo,sysConfigMain,CopyOptions.create().ignoreNullValue());
        baseService.saveOrUpdate(sysConfigMain);
        return Result.ok();
    }
    @DeleteMapping
        public Result del(@RequestParam(required = false) String id ){
        baseService.removeById(id);
        return Result.ok();
    }
    @GetMapping
    public Result view(@RequestParam(required = false) String id ){
        SysConfigMainVo sysConfigMainVo = new SysConfigMainVo();
        SysConfigMain sysConfigMain = baseService.getById(id);
        BeanUtil.copyProperties(sysConfigMain,sysConfigMainVo,CopyOptions.create().ignoreNullValue());
        return Result.ok().addData(sysConfigMain);
    }
}
